package com.example.service.impl;

import com.example.interceptor.LoginInterceptor;
import com.example.mapper.CategoryMapper;
import com.example.pojo.Category;
import com.example.service.CategoryService;
import com.example.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> getAllCategory() {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer createUser = (Integer) map.get("id");
        return categoryMapper.getAllCategory(createUser);
    }

    @Override
    public void addNewCategory(Category category) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer createUser = (Integer) map.get("id");
        category.setCreateUser(createUser);
        categoryMapper.addNewCategory(category);
    }

    @Override
    public Category getCategoryById(int id) {
        return categoryMapper.getCategoryById(id);
    }

    @Override
    public void updateCategory(Category category) {
        categoryMapper.updateCategory(category);
    }

    @Override
    public void deleteCategoryById(int id) {
        categoryMapper.deleteCategoryById(id);
    }
}
